
import apis from '../../http/apis/apis'
export default {
    namespaced: true,
    state: {
        ordersData: [],
        total: 0,
        pages: 0,
        currentPage: 1,
        pageSize: 2,
        stateData: [],
    },
    mutations: {
        // 获取全部
        getOrdersData(state, newDta) {
            state.ordersData = newDta.result
            state.total = newDta.total
            state.pages = newDta.pages
            state.searchData = newDta.searchData
        },
        // 订单状态
        changeOrders(state, newState) {
            state.stateData = newState
        },
        // 分页
        changePageSize(state, pageSize) {
            state.pageSize = pageSize
        },
        changeCurrentPage(state, currentPage) {
            state.currentPage = currentPage
        },
        firstPage(state) {
            state.currentPage = 1
        },
        lastPage(state) {
            state.currentPage = state.pages
        },
        prevPage(state) {
            state.currentPage--;
        },
        nextPage(state) {
            state.currentPage++;
        },
    },
    actions: {
        // 获取
        async getOrders(context, searchData) {
            // console.log(searchData);
            const { data } = await apis.orders.getOrders({
                // 分页数据
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
                // 搜索数据
                value: searchData.value,
                input: searchData.input,
                state: searchData.state,
            });
            if (data.status) {
                context.commit('getOrdersData', data.data)
            }
        },
        // 删除
        async deleteOrders(context, num) {
            // console.log(num);
            const { data } = await apis.orders.deleteOrders(num._id);
            if (data.status) {
                context.dispatch("getOrders", num);
            }
        }

    }
}